package com.zhijian.medical.controller;

import com.zhijian.medical.annotation.Response;
import com.zhijian.medical.entity.po.DeviceCategoryAdjustParameter;
import com.zhijian.medical.entity.vo.request.DeviceCategoryAdjustParameterSearchVo;
import com.zhijian.medical.entity.vo.response.DeviceCategoryAdjustParameterVo;
import com.zhijian.medical.service.DeviceCategoryAdjustParameterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 设备品类校准参数 控制层
 *
 * @author HCG
 * @version 1.0
 * @date 2022-01-17 15:45:16
 */
@Slf4j
@Controller
@Api(tags = "设备品类校准参数")
public class DeviceCategoryAdjustParameterController {

    @Autowired
    private DeviceCategoryAdjustParameterService service;

    /**
     * 保存
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("/adjust/parameter")
    @ApiOperation("新增")
    public boolean insert(@RequestBody List<DeviceCategoryAdjustParameter> param) {
        log.info("{} - {}| insert info", this.getClass().getSimpleName(), param);
        return service.saveAll(param);
    }

    /**
     * 删除
     *
     * @param id
     * @return
     */
    @Response
    @DeleteMapping("/adjust/parameter/{id}")
    @ApiOperation("删除")
    public boolean delete(@PathVariable("id") Long id) {
        log.info("{} - {}| delete info", this.getClass().getSimpleName(), id);
        service.deleteById(id);
        return true;
    }

    /**
     * 根据设备id查询列表
     *
     * @param deviceId
     * @return
     */
    @Response
    @GetMapping("/adjust/parameter/device/{deviceId}")
    @ApiOperation("根据设备id查询列表")
    public List<DeviceCategoryAdjustParameterVo> selectByDeviceId(@PathVariable("deviceId") Long deviceId) {
        return service.selectByDeviceId(deviceId);
    }

    /**
     * 根据品类id列表查询，不分页
     *
     * @param categoryId
     * @return
     */
    @Response
    @GetMapping("/adjust/parameter/list/{categoryId}")
    @ApiOperation("根据品类id列表查询，不分页")
    public List<DeviceCategoryAdjustParameterVo> selectList(@PathVariable("categoryId") Long categoryId) {
        return service.selectList(DeviceCategoryAdjustParameterSearchVo.builder()
                .categoryId(categoryId)
                .build());
    }

}